import { getTemplateData, GetGiftData, GetTaskData, GetLimitedGift } from '@/api/request'
import { getFDate } from '@/Utils/utils'
const state = {
    temp_style: '',
    act_title: '',
    icon_url: '',
    user_name: '',
    exe: 0,
    st_time: '',
    ed_time: '',
    icon_primary_pass: '',
    name_primary_pass: '',
    price_primary_pass: '',
    goods_primary_isfree: false,
    flag_primary_pass: '',
    name_advanced_pass: '',
    price_advanced_pass: '',
    icon_advacned_pass: '',
    icon_exe: '',
    price_exe: '',
    jump_url: '',
    task_ed_time: '',
    level: 0,
    flag_refreshed: true,
    goodsid_primary_pass: '',
    goodsid_advanced_pass: '',
    map_id: 0,
    goodsid_exe: ''
}

const mutations = {
    Change_Base(state, { data }) {
        state.temp_style = data.temp_style;
        state.act_title = data.act_title;
        state.icon_url = data.icon_url;
        state.user_name = data.user_name;
        state.exe = data.exe;
        state.st_time = getFDate(data.st_time);
        state.ed_time = getFDate(data.ed_time);
        state.task_ed_time = getFDate(data.task_ed_time);
        state.icon_primary_pass = data.icon_primary_pass;
        state.name_primary_pass = data.name_primary_pass;
        state.price_primary_pass = data.price_primary_pass;
        state.goods_primary_isfree = data.goods_primary_isfree;
        state.flag_primary_pass = data.flag_primary_pass;
        state.name_advanced_pass = data.name_advanced_pass;
        state.price_advanced_pass = data.price_advanced_pass;
        state.icon_advacned_pass = data.icon_advacned_pass;
        state.icon_exe = data.icon_exe;
        state.price_exe = data.price_exe;
        state.jump_url = data.jump_url;
        state.level = data.level;
        state.flag_refreshed = data.flag_refreshed;
        state.goodsid_primary_pass = data.goodsid_primary_pass;
        state.goodsid_advanced_pass = data.goodsid_advanced_pass;
        state.map_id = data.map_id;
        state.goodsid_exe = data.goodsid_exe;
    }
}

const actions = {
    getTemplateData({ commit }, { id }) {
        console.log(id)
        return getTemplateData(id).then(res => {
            commit('Change_Base', { data: res.data })
            console.log(res)
            return new Promise((resolve, reject) => {
                if (res.errCode == 0) {
                    resolve(res)
                } else {
                    reject(res.msg)
                }
            })

        })
    },
    GetGiftDataAction({ commit }, { id }) {
        return GetGiftData(id)
    },
    GetTaskDataFn({ commit }, { id }) {
        return GetTaskData(id)
    },
    GetLimitedGiftAction({ commit }, { id }) {
        return GetLimitedGift(id)
    }


}

export default {
    namespaced: true,
    state,
    mutations,
    actions
}